<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Swagger UI</title>
    <link rel="stylesheet" type="text/css" href="swagger-ui.css">
    <style>
        html {
            box-sizing: border-box;
            overflow: -moz-scrollbars-vertical;
            overflow-y: scroll;
        }

        *,
        *:before,
        *:after {
            box-sizing: inherit;
        }

        body {
            margin: 0;
            background: #fafafa;
        }
    </style>
</head>

<body>

<div id="swagger-ui"></div>

<script src="swagger-ui-bundle.js"></script>
<script src="swagger-ui-standalone-preset.js"></script>
<script>
   window.onload = function () {
       // Custom plugin that adds extra stuff
       const TextAreaPlugin = function() {
           return {
               wrapComponents: {
                   // add text above InfoContainer - same effect as above title
                   JsonSchema_string: (Original, runtime) => (props) => {
                       var React = runtime.React,
                           schema = props.schema || {},
                           errors = props.errors || {},
                           format = schema.format || "",
                           isDisabled = props.disabled || (schema["in"] === "formData" && !("FormData" in window));

                        errors = errors.toJS ? errors.toJS() : []

                       function handleOnChange(e) {
                           const inputValue = e.target.value;

                           props.onChange(inputValue)
                       }

                       if (format == "textarea") {
                           return React.createElement("div", null,
                                   React.createElement("textarea", {
                                       title: errors.length ? errors : "",
                                       className: errors.length ? "invalid" : "",
                                       value: props.value,
                                       disabled: isDisabled,
                                       onChange: handleOnChange
                                   })
                           )
                       }

                       return React.createElement(Original, props);
                   },
                   // add text above InfoContainer - same effect as above title
                   InfoBasePath: (Original, runtime) => (props) => {
                       var React = runtime.React,
                           paths = location.pathname.split("/");
                    
                       props.host = location.host;
                       paths.pop();
                       paths.pop();
                       props.basePath = paths.join("/");

                       return React.createElement(Original, props);
                   },
               }
           }
       };

        // Begin Swagger UI call region
        var ui = SwaggerUIBundle({
            url: "./swagger.json",
            requestInterceptor: function (request) {
                // Replace the default host by the correct one.
                // DO NOT CHANGE here without changing application.conf
                request.url = request.url.replace("API_HOST", location.host);
                return request;
            },
            dom_id: '#swagger-ui',
            deepLinking: true,
            presets: [
                SwaggerUIBundle.presets.apis,
                SwaggerUIStandalonePreset
            ],
            plugins: [
                TextAreaPlugin,
                SwaggerUIBundle.plugins.DownloadUrl
            ],
            layout: "StandaloneLayout"
        });
        // End Swagger UI call region

        window.ui = ui
    }
</script>
</body>
</html>
